package com.wc.alorithm_luogu.P3392;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;


/**
 * @Author congege
 * @Description 涂国旗
 * https://www.luogu.com.cn/problem/P3392
 * @Date Created in 2023/9/21-18:28
 */

public class Main {
    public static void main(String[] args) throws Exception {
        Input scan = new Input();

        int n = scan.nextInt();
        int m = scan.nextInt();

        char[][] map = new char[n][m];
        for (int i = 0; i < n; i++) {
            map[i] = scan.next().toCharArray();
        }

        /**
         * 每一行
         * int[i][0] 表示该行白色的个数
         * int[i][1] 表示该行蓝色的个数
         * int[i][2] 表示改行红色的个数
         */
        int[][] rowColorNumber = new int[n][3];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                switch (map[i][j]) {
                    case 'W': {
                        rowColorNumber[i][0]++;
                        break;
                    }
                    case 'B': {
                        rowColorNumber[i][1]++;
                        break;
                    }
                    case 'R': {
                        rowColorNumber[i][2]++;
                        break;
                    }
                }
            }
        }
        /**
         * 每一行
         * int[i][0] 表示该行涂成白色需要涂的个数
         * int[i][1] 表示该行涂成蓝色需要涂的个数
         * int[i][2] 表示改行涂成红色需要涂的个数z
         */
        int[][] rowBlockNumber = new int[n][3];

        for (int i = 0; i < n; i++) {
            rowBlockNumber[i][0] = rowColorNumber[i][1] + rowColorNumber[i][2];
            rowBlockNumber[i][1] = rowColorNumber[i][0] + rowColorNumber[i][2];
            rowBlockNumber[i][2] = rowColorNumber[i][0] + rowColorNumber[i][1];
        }

        int ans = Integer.MAX_VALUE;
        /**
         * 暴力计算
         */
        int curBlock;

        int whiteBlock;
        for (int i = 0; i < n - 2; i++) {
            curBlock = 0;
            /**
             * 0 到 i 层涂白色
             */
            for (int j = 0; j <= i; j++) {
                curBlock += rowBlockNumber[j][0];
            }
            whiteBlock = curBlock;
            for (int j = i + 1; j < n - 1; j++) {
                /**
                 * i+1层 到 j 层的涂蓝色
                 */
                for (int k = i + 1; k <= j; k++) {
                    curBlock += rowBlockNumber[k][1];
                }
                /**
                 * j+1层到 n-1 层涂红色
                 */
                for (int k = j + 1; k < n; k++) {
                    curBlock += rowBlockNumber[k][2];
                }
                ans = Math.min(curBlock, ans);
                curBlock = whiteBlock;
            }
        }
        System.out.println(ans);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public String next() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return in.sval;
        }

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
